do "E:\yungyu\lottery_baby\do\set_environment.do"

clear
set more off

global control1 "i.pers_gender i.houhld_resid_cd pers_income_pre1 pers_asset_pre1 pers_earnings_pre1 pers_labor_pre1 married_pre1 totbaby_pre1"
global control2 "totbaby_pre1"
global control3 "pre*redeem*"
global control4 "i.child_gender i.child_born_place_cd i.child_birth_order i.child_born_month"

use "$wdata\project_lottery_child_quality_b3a6_first_5k.dta", clear

gen child_win_age = win_year - child_born_year
replace child_age = year - child_born_year
gen anycollege = anycollege_ibr == 1 | anycollege_ibe == 1
 
keep if child_win_age <= 17

recode anytop1 . = 0
recode anytop5 . = 0
recode anytop10 . = 0
rename anycollege_ibr anydomestic

encode child_born_place, gen(child_born_place_cd)
recode child_born_month . = 0
recode child_born_place_cd . = 0

cap rm "$table/temp/Tab7.txt"
cap rm "$table/temp/Tab7.xls"

foreach y in anycollege anydomestic anytop1 anytop5 anytop10 anyoversea {
	sum `y' if child_age == 19 & current == 0 & prize10M < 5
	loc bm = r(mean)
	
	reg `y' currentxprize prize10M current i.child_born_year i.year $control1 $control2  $control3 $control4 if child_age == 19 & prize10M < 5, robust cl(houseid)
	outreg2 using "$table/temp/Tab7.xls" , append bd(3) sd(3) nocon keep(currentxprize) addtext(Baseline, `bm') ctitle(`y',+ Z)
	
}

import delimited using "$table/temp/Tab7.txt", clear
export excel "$table/Tables.xlsx", sheet("Tab7") sheetreplace
